package com.ruoyi.jl_base.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jl_base.domain.vo.JlBaseBaContractSheetVo;
import com.ruoyi.jl_base.domain.bo.JlBaseBaContractSheetBo;
import com.ruoyi.jl_base.service.IJlBaseBaContractSheetService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工程量清单
 *
 * @author zyb
 * @date 2024-12-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/jl_base/baseBaContractSheet")
public class JlBaseBaContractSheetController extends BaseController {

    private final IJlBaseBaContractSheetService iJlBaseBaContractSheetService;

    /**
     * 查询工程量清单列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<JlBaseBaContractSheetVo> list(JlBaseBaContractSheetBo bo, PageQuery pageQuery) {
        return iJlBaseBaContractSheetService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工程量清单列表
     */
    @SaCheckLogin
    @Log(title = "工程量清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(JlBaseBaContractSheetBo bo, HttpServletResponse response) {
        List<JlBaseBaContractSheetVo> list = iJlBaseBaContractSheetService.queryList(bo);
        ExcelUtil.exportExcel(list, "工程量清单", JlBaseBaContractSheetVo.class, response);
    }

    /**
     * 获取工程量清单详细信息
     *
     * @param sheetId 主键
     */
    @SaCheckLogin
    @GetMapping("/{sheetId}")
    public R<JlBaseBaContractSheetVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long sheetId) {
        return R.ok(iJlBaseBaContractSheetService.queryById(sheetId));
    }

    /**
     * 新增工程量清单
     */
    @SaCheckLogin
    @Log(title = "工程量清单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody JlBaseBaContractSheetBo bo) {
        return toAjax(iJlBaseBaContractSheetService.insertByBo(bo));
    }

    /**
     * 修改工程量清单
     */
    @SaCheckLogin
    @Log(title = "工程量清单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody JlBaseBaContractSheetBo bo) {
        return toAjax(iJlBaseBaContractSheetService.updateByBo(bo));
    }

    /**
     * 删除工程量清单
     *
     * @param sheetIds 主键串
     */
    @SaCheckLogin
    @Log(title = "工程量清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sheetIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] sheetIds) {
        return toAjax(iJlBaseBaContractSheetService.deleteWithValidByIds(Arrays.asList(sheetIds), true));
    }
}
